{extend name="normal_base" /}
{block name="navigation"}{/block}
{block name="body"}
<div class="x-body">
    <form action="{:url('ContractType/edit')}" method="post" class="layui-form layui-form-pane" id="from_id">
        <div class="layui-form-item">
            <label class="layui-form-label">父级分类</label>
            <div class="layui-input-block">
                <select name="parent_id" lay-verify="required">
                    <option value="0">一级分类</option>
                    {foreach name="top_type_list" item="vo"}
                    <option value="{$vo.id}" {if condition="$type_info['parent_id']==$vo.id"} selected="selected"{/if}>{$vo.type}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                业务类型
            </label>
            <div class="layui-input-block">
                <input type="text" id="title" name="type" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$type_info['type']}">
            </div>
        </div>

        <div class="layui-form-item">
            <input type="hidden" name="id" value="{$type_info['id']}">
            <button class="layui-btn" lay-submit="" lay-filter="edit">修改</button>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;

        //监听提交
        form.on('submit(edit)', function(data){
            //console.log(data);
            //发异步，把数据提交给php
            $("#from_id").ajaxSubmit({
                /*beforeSubmit:function () {
                    //表单提交前
                },*/
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                            //刷新父层页面
                            parent.location.replace(parent.location.href);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}